/*
 * Copyright (C) 2012 Santiago Valdarrama
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.yuanmei.stockeyes.model;

import java.util.LinkedList;

import android.content.Context;
import com.yuanmei.stockeyes.model.Stock;
import com.yuanmei.stockeyes.model.PolicyBase;

public class StockAnalysis {
    private LinkedList<PolicyBase> mPolicyList;
    //private Context mContext;
    private static StockAnalysis sInstance = null;
    
    private StockAnalysis(Context context) {
        // mContext    = context.getApplicationContext();
        mPolicyList = new LinkedList<PolicyBase>();
    }
    public boolean addPolicy(PolicyBase policy) {
        return mPolicyList.add(policy);
    }
    
    public void emptyPolicy(PolicyBase policy) {
        mPolicyList.clear();
    }

    public String analyseByPolices(Stock stock) {

        for(PolicyBase p : mPolicyList){
            String match_result = p.matchResults(stock);
            if (null != match_result) {
                return match_result;
            }
        }

        return null;
    }
    
    public static StockAnalysis getInstance(Context context) {
        if (null == sInstance) {
            sInstance = new StockAnalysis(context);
        }
        return sInstance;
    }
}
